#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll lowbit(ll i) {return i&-i;}

void add(vector<ll> &a, ll p, ll v){
    while(p <= a.size()-1){
        a[p] += v;
        p += lowbit(p);
    }
}

long long sum(vector<ll> &a, ll p){
    ll s = 0;
    while(p){
        s += a[p];
        p -= lowbit(p);
    }
    return s;
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    ll N; cin >> N;
    vector<pair<ll, ll> > in(N+1);
    vector<ll> v(N+1);
    for (ll i = 1; i <= N; ++i) {
        cin >> in[i].first;
    }
    for (ll i = 1; i <= N; ++i) {
        cin >> in[i].second;
        v[i] = in[i].second;
    }
    v[0] = INT_MIN;
    sort(in.begin(), in.end());
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());

    vector<ll> cnt(v.size(), 0), vx(v.size(), 0);
    ll ans = 0;
    for (ll i = 1; i <= N; ++i) {
        ll pos = lower_bound(v.begin(), v.end(), in[i].second) - v.begin();
        ans += sum(cnt, pos)*in[i].first - sum(vx, pos);
        add(cnt, pos, 1);
        add(vx, pos, in[i].first);
    }
    cout << ans;
    return 0;

}